package com.xjrsoft.module.customerTwo.AppManage.service_support_order.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.core.tool.utils.BeanUtil;
import com.xjrsoft.core.tool.utils.FlowableUtil;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.dto.SaveServiceSupportOrderTableFormDataDto;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.dto.ServiceSupportOrderTableDto;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.dto.ServiceSupportOrderTableListDto;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.entity.ServiceSupportOrderTable;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.service.IServiceSupportOrderService;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.service.IServiceSupportOrderTableService;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.vo.ServiceSupportOrderTableListVo;
import com.xjrsoft.module.customerTwo.AppManage.service_support_order.vo.ServiceSupportOrderTableVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *  控制器
 *
 * @author lisen
 * @since 2024-04-24
 */
@RestController
@AllArgsConstructor
@RequestMapping("/servicesupportordertable")
@Api(value = "servicesupportordertable", tags = "servicesupportordertable接口")
public class ServiceSupportOrderTableController {


	@Resource
	IServiceSupportOrderService serviceSupportOrderService;


	/**
	 * 详情 
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入serviceSupportOrderTable")
	@SaCheckPermission(value = {"servicesupportordertable:view", "servicesupportordertable:modify"}, mode = SaMode.OR)
	public Response<ServiceSupportOrderTableVo> getFormData(@PathVariable Integer id) {
		// 主表数据
		ServiceSupportOrderTable serviceSupportOrderTable = serviceSupportOrderService.getTableById(id);
		ServiceSupportOrderTableVo serviceSupportOrderTableVo = BeanUtil.copy(serviceSupportOrderTable, ServiceSupportOrderTableVo.class);
		return Response.ok(serviceSupportOrderTableVo);
	}

	/**
	 * 自定义分页 
	 */
	@GetMapping
	@ApiOperation(value = "分页", notes = "传入serviceSupportOrderTable")
		public Response<PageOutput<ServiceSupportOrderTableListVo>> getPageList(ServiceSupportOrderTableListDto listDto) {
		IPage<ServiceSupportOrderTable> page = serviceSupportOrderService.getPageList(listDto);
		List<ServiceSupportOrderTableListVo> records = BeanUtil.copyList(page.getRecords(), ServiceSupportOrderTableListVo.class);
			// 工作流数据处理
		FlowableUtil.systemFormList(records, SecureUtil.getModuleId());
		return Response.ok(ConventPage.getPageOutput(page.getTotal(), records));
	}

	/**
	 * 新增 
	 */
	//商户处理接口
	@PostMapping
	@ApiOperation(value = "新增", notes = "传入serviceSupportOrderTable")
	@SaCheckPermission("servicesupportordertable:add")
	public Response save(@RequestBody SaveServiceSupportOrderTableFormDataDto formDto) {
		ServiceSupportOrderTableDto serviceSupportOrderTableDto = formDto.getServiceSupportOrderTableDto();
		ServiceSupportOrderTable serviceSupportOrderTable = BeanUtil.copy(serviceSupportOrderTableDto, ServiceSupportOrderTable.class);
		String dataId = serviceSupportOrderService.addServiceSupportOrderTable(serviceSupportOrderTable);
		return dataId == null ? Response.notOk() : Response.ok(dataId);
	}

	/**
	 * 修改 
	 */
	@PutMapping("/{id}")
	@ApiOperation(value = "修改", notes = "传入serviceSupportOrderTable")
	@SaCheckPermission("servicesupportordertable:modify")
	public Response update(@PathVariable String id, @RequestBody SaveServiceSupportOrderTableFormDataDto formDto) {
		ServiceSupportOrderTableDto serviceSupportOrderTableDto = formDto.getServiceSupportOrderTableDto();
		ServiceSupportOrderTable serviceSupportOrderTable = BeanUtil.copy(serviceSupportOrderTableDto, ServiceSupportOrderTable.class);
		return Response.status(serviceSupportOrderService.updateServiceSupportOrderTable(id, serviceSupportOrderTable));
	}



	/**
	 * 删除 
	 */
	@DeleteMapping("/{ids}")
	@ApiOperation(value = "删除", notes = "传入ids")
	@SaCheckPermission(value = {"servicesupportordertable:batchDelete", "servicesupportordertable:delete"}, mode = SaMode.OR)
	public Response remove(@ApiParam(value = "主键集合", required = true) @PathVariable String ids) {
		return Response.status(serviceSupportOrderService.deleteTable(ids));
	}


}
